package com.triptogether.services;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;

public class ServicesQueuesManager {

	private static ServicesQueuesManager instance;
	private Queue<Map<String, String>> chatMessagesQueue;

	private ServicesQueuesManager() {
		chatMessagesQueue = new LinkedList<Map<String, String>>();
	}

	public static ServicesQueuesManager getInstance() {
		if (instance == null) {
			instance = new ServicesQueuesManager();
		}

		return instance;
	}

	// //////////////////////////////////
	// Chat messages queue manage
	// //////////////////////////////////

	public static final String KEY_FROM_USER = "fromUser";
	public static final String KEY_TO_USER = "toUser";
	public static final String MESSAGE_KEY = "messageText";

	public void addChatMessageToQueue(String fromUserFacebookId, String toUserFacebookId, String message) {
		Map<String, String> newMessage = new HashMap<String, String>();
		newMessage.put(KEY_FROM_USER, fromUserFacebookId);
		newMessage.put(KEY_TO_USER, toUserFacebookId);
		newMessage.put(MESSAGE_KEY, message);

		addChatMessageToQueue(newMessage);
	}

	public void addChatMessageToQueue(Map<String, String> messageMap) {
		chatMessagesQueue.add(messageMap);
	}

	public Map<String, String> getChatMessageAndRemove() {
		return chatMessagesQueue.poll();
	}

	public boolean isChatMessagesQueueEmpty() {
		return chatMessagesQueue.isEmpty();
	}

	// //////////////////////////////////
	// End Chat messages queue manage
	// //////////////////////////////////
}
